<?php
class NWPFormatting {
function wp_parse_str( $string, &$array ) {
	parse_str( $string, $array );
	if ( get_magic_quotes_gpc() )
		$array = self::stripslashes_deep( $array ); // parse_str() adds slashes if magicquotes is on.  See: http://php.net/parse_str
	$array = NWPPlugin::apply_filters( 'wp_parse_str', $array );
}
function stripslashes_deep($value) {
	 $value = is_array($value) ?
		 array_map('stripslashes_deep', $value) :
		 stripslashes($value);

	 return $value;
}

/**
 * Escapes text for SQL LIKE special characters % and _
 *
 * @param string text the text to be escaped
 * @return string text, safe for inclusion in LIKE query
 */
function like_escape($text) {
	return str_replace(array("%", "_"), array("\\%", "\\_"), $text);
}
function format_to_edit($content, $richedit = false) {
	$content = NWPPlugin::apply_filters('format_to_edit', $content);
	if (! $richedit )
		$content = htmlspecialchars($content);
	return $content;
}
// Escaping for HTML attributes
function attribute_escape($text) {
	$safe_text = self::wp_specialchars($text, true);
	return NWPPlugin::apply_filters('attribute_escape', $safe_text, $text);
}
function wp_specialchars( $text, $quotes = 0 ) {
	// Like htmlspecialchars except don't double-encode HTML entities
	$text = str_replace('&&', '&#038;&', $text);
	$text = str_replace('&&', '&#038;&', $text);
	$text = preg_replace('/&(?:$|([^#])(?![a-z1-4]{1,8};))/', '&#038;$1', $text);
	$text = str_replace('<', '&lt;', $text);
	$text = str_replace('>', '&gt;', $text);
	if ( 'double' === $quotes ) {
		$text = str_replace('"', '&quot;', $text);
	} elseif ( 'single' === $quotes ) {
		$text = str_replace("'", '&#039;', $text);
	} elseif ( $quotes ) {
		$text = str_replace('"', '&quot;', $text);
		$text = str_replace("'", '&#039;', $text);
	}
	return $text;
}
// Escape single quotes, specialchar double quotes, and fix line endings.
function js_escape($text) {
	$safe_text = self::wp_specialchars($text, 'double');
	$safe_text = preg_replace('/&#(x)?0*(?(1)27|39);?/i', "'", stripslashes($safe_text));
	$safe_text = preg_replace("/\r?\n/", "\\n", addslashes($safe_text));
	return NWPPlugin::apply_filters('js_escape', $safe_text, $text);
}
function sanitize_title($title, $fallback_title = '') {
	$title = strip_tags($title);
	$title = NWPPlugin::apply_filters('sanitize_title', $title);

	if ( '' === $title || false === $title )
		$title = $fallback_title;

	return $title;
}
}
?>